package cn.maihe.elg.operation.web.system;

import cn.maihe.elg.operation.model.vo.system.OrgQualificationVO;
import cn.maihe.elg.operation.model.vo.Query;
import cn.maihe.elg.operation.repository.entity.OrgQualificationDO;
import cn.maihe.elg.operation.service.system.OrgQualificationService;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author JHWei on 2018-07-13.
 * @ 创建日期：2018-07-13
 */
@Api(value = "机构资质管理接口", tags = {"机构资质管理"})
@RestController
public class OrgQualificationController {

    @Resource
    private OrgQualificationService orgQualificationService;

    @ApiOperation(value = "新增机构资质")
    @RequestMapping(value = "/api/orgQualification", method = RequestMethod.POST)
    public void createOrgQualification(@RequestBody OrgQualificationVO createOrgQualificationVO) {
        OrgQualificationDO orgQualification = new OrgQualificationDO();
        BeanUtils.copyProperties(createOrgQualificationVO, orgQualification);
        orgQualificationService.createOrgQualification(orgQualification);
    }

    @ApiOperation(value = "查询机构资质列表", notes = "根据机构编号查询机构资质列表")
    @RequestMapping(value = "/api/orgQualification/list", method = RequestMethod.POST)
    public PageInfo<OrgQualificationDO> findAll(@RequestBody Query query) {
        return orgQualificationService.findOrgQualificationByPage(query);
    }

    @ApiOperation(value = "获取机构资质详情")
    @RequestMapping(value = "/api/orgQualification/{id}", method = RequestMethod.GET)
    public OrgQualificationDO getOrgQualification(@PathVariable Long id) {
        return orgQualificationService.getOrgQualification(id);
    }

    @ApiOperation(value = "修改机构资质信息")
    @RequestMapping(value = "/api/orgQualification", method = RequestMethod.PUT)
    public void updateOrgQualification(@RequestBody OrgQualificationVO updateOrgQualificationVO) {
        OrgQualificationDO orgQualification = new OrgQualificationDO();
        BeanUtils.copyProperties(updateOrgQualificationVO, orgQualification);
        orgQualificationService.modifyOrgQualification(orgQualification);
    }

    @ApiOperation(value = "删除机构资质")
    @RequestMapping(value = "/api/orgQualification/{id}", method = RequestMethod.DELETE)
    public void deleteOrgQualification(@PathVariable Long id) {
        orgQualificationService.deleteOrgQualification(id);
    }
}
